import { Get } from '@/api/axios';
import echarts, { EChartOption } from "echarts";

export async function option(param: { name: string, value: number }[]): Promise<EChartOption> {
    const geoJson = await Get({ url: '/geoJson.json' })
    echarts.registerMap('china', geoJson.data);
    return {
        tooltip: {
            trigger: "item",
            formatter: (p: { value: any; name: string; }) => {
                let val = p.value;
                if (window.isNaN(val)) {
                    val = 0;
                }
                let txtCon =
                    "<div style='text-align:center'>" + p.name + ":<br />下载量：" + val + '</div>';
                return txtCon;
            }
        },
        series: [{
            type: 'map',
            roam: false,
            label: {
                normal: {
                    show: true,
                    textStyle: {
                        color: '#1DE9B6'
                    }
                },
                emphasis: {
                    textStyle: {
                        color: '#000'
                    }
                }
            },
            itemStyle: {
                normal: {
                    borderColor: 'rgb(147, 235, 248)',
                    borderWidth: 1,
                    areaColor: {
                        type: 'radial',
                        x: 0.5,
                        y: 0.5,
                        r: 0.8,
                        colorStops: [{
                            offset: 0,
                            color: '#09132c'
                        }, {
                            offset: 1,
                            color: '#274d68'
                        }],
                        globalCoord: true
                    },
                },
                emphasis: {
                    areaColor: 'rgb(46,229,206)',
                    borderWidth: 0.1
                }
            },
            zoom: 1,
            left: 0,
            right: '1%',
            top: '10%',
            map: 'china',
            data: param
        }]
    } as unknown as EChartOption
}
